//
//  SAIndexActivityView.m
//  YunFu
//
//  Created by Bager on 2018/9/10.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "SAIndexActivityView.h"

#import "SAIndexActivityCell.h"

@implementation SAIndexActivityView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = HexColor(0xf4f5f6);
        [self createView];
        [self createTitleView];
    }
    return self;
}

- (void)createTitleView
{
    UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(80, 24, kScreenWidth - 80 * 2, 1)];
    line.backgroundColor = HexColor(0x0c97ec);
    [self addSubview:line];
    
    UILabel *lineText = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 2.0 - 65, 0, 130, 50)];
    lineText.text = @"精彩活动";
    lineText.font = [UIFont systemFontOfSize:14];
    lineText.textAlignment = NSTextAlignmentCenter;
    lineText.backgroundColor = HexColor(0xf4f5f6);
    lineText.textColor = HexColor(0x0c97ec);
    [self addSubview:lineText];
}

- (void)createView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置每个item的大小，
    flowLayout.itemSize = CGSizeMake(kScreenWidth / 3.0, 150);
    // 设置列的最小间距
    flowLayout.minimumInteritemSpacing = 0;
    // 设置最小行间距
    flowLayout.minimumLineSpacing = 0;
    // 设置布局的内边距
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    // 滚动方向
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.shopCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, kScreenWidth, 150)  collectionViewLayout:flowLayout];
    
    self.shopCollectionView.backgroundColor = [UIColor whiteColor];
    
    self.shopCollectionView.dataSource = self;
    
    self.shopCollectionView.delegate = self;
    
    [self.shopCollectionView registerClass:[SAIndexActivityCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
    
    [self addSubview:self.shopCollectionView];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    SAIndexActivityCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor orangeColor];
    
    NSArray *imgArray = @[@"yf1-tg1",@"yf1-tg2",@"yf1-tg3"];
    NSArray *nameArray = @[@"新人特惠",@"淘货攻略",@"口碑好物"];
    NSArray *detailArray = @[@"满38包邮>",@"满38包邮>",@"满38包邮>"];
    NSArray *colorArray = @[HexColor(0xee6c6a),HexColor(0x60c9f8),HexColor(0xffc557)];
    NSArray *bgColorArray = @[HexColor(0xfcf0f2),HexColor(0xeef8fc),HexColor(0xfcf9ee)];
    
    [cell.img setImage:[UIImage imageNamed:imgArray[indexPath.item]]];
    cell.name.text = nameArray[indexPath.item];
    cell.detail.text = detailArray[indexPath.item];
    cell.backgroundColor = bgColorArray[indexPath.item];
    cell.line.backgroundColor = colorArray[indexPath.item];
    cell.name.textColor = colorArray[indexPath.item];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}

@end
